package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/images")
public class ImagesController {


    //将图片保存到本地
    @PostMapping
    public Object upload(MultipartFile upload){
        Map<String,Object> map = new HashMap<>();
        try {
            String url = UploadUtil.upload(upload);
            map.put("uploaded",1);
            map.put("url",url);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("uploaded",0);
            HashMap<String,Object> msg = new HashMap<>();
            map.put("error",msg.put("message",e.getMessage()));
        }
        return map;
    }
}
